奥义思网站建设-www.aooly.com
奥义思坚信质量高于产量
我们的团队自成立以来,秉承着质量是衡量价值最重要标准的理念,致力于打造高品质数字产品。不放过任何一个小的瑕疵而一蹴而就,体现的不仅是我们对品质的苛求,也是对客户以及产品负责的态度。
马上联系我们,让天才的设计师帮您实现这一切。

    CSS完全教程6 颜色和背景(Color and Background)属性:

      4、颜色和背景(Color and Background)属性:

       

      这里介绍有关CSS中前景色和背景颜色、图片的设定方法。

       

      color属性:

      color属性用于设定元素的前景色:

      属性名称: 'color'
      属性值: <color>
      初始值: 根据用户的初始值而定
      适合对象: 所有元素
      是否继承: yes
      百分比备注: 被禁止

      color属性的值可以是十六进制数值、rgb()函数或CSS承认的颜色名称。如:

      EM { color: red }
      EM { color: rgb(255,0,0) }

      背景属性:

      background-color属性用于设定背景色,初始值为透明:

      属性名称: 'background-color'
      属性值: <color> | transparent
      初始值: transparent
      适合对象: 所有元素
      是否继承: no
      百分比备注: 被禁止


      backgroud-image属性用于设定背景的图片:

      属性名称: 'background-image'
      属性值: <url> | none
      初始值: none
      适合对象: 所有元素
      是否继承: no
      百分比备注: 被禁止

       

      其中url可以为绝对地址,也可以是相对地址,例如:

      BODY { background-image: url(marble.gif) }
      P { background-image: none }

       

      以上两个属性利用普通的HTML属性也可以实现,下面的属性是CSS对原有HTML的扩展。
      background-repeat属性用来描述背景图片的重复排列方式:

      属性名称: 'background-repeat'
      属性值: repeat | repeat-x | repeat-y | no-repeat
      初始值: repeat
      适合对象: 所有元素
      是否继承: no
      百分比备注: 被禁止

       

      其中属性值的含义为:
      repeat:沿X轴和Y轴两个方向重复显示图片。
      repeat-x:沿X轴方向重复图片。
      repeat-y:沿Y轴方向重复图片。
      none:不重复图片。

      例如:

      BODY {
      background: red url(pendant.gif);
      background-repeat: repeat-y;
      }
      /*
      表示沿Y轴重复图片"pendant.gif",其余部分以红色为背景色*/

      background-attachment属性表示在滚动整个文档时,背景图片的显示方式。它的属性值有两种:fixedscrollfixed相当于IE4里的水印效果,也就是说在拖动文档时,背景相对是静止的,scroll则和文档一起滚动。

      background-position属性用来指定背景图片显示的位置:

      属性名称: 'background-position'
      属性值: [<percentage> | <length> ]{1,2} | [top | center | bottom] || [left | center | right]
      初始值: 0% 0%
      适合对象: 容器元素
      是否继承: no
      百分比备注
      : refer to the size of the element itself

       

      其中属性值含义为:
      "top left""left top"表示"0% 0%"
      "top""top center""center top"表示"50% 0%"
      "right top""top right"都表示"100% 0%"
      "left""left center""center left"表示"0% 50%"
      "center""center center"表示"50% 50%"
      "right""right center""center right"都表示"100% 50%"
      "bottom left""left bottom"表示"0% 100%"
      "bottom""bottom center""center bottom"都表示"50% 100%"
      "bottom right"
      "right bottom"表示"100% 100%"


      例如:

      BODY { background: url(banner.jpeg) right top } /* 100% 0% */
      BODY { background: url(banner.jpeg) top center } /* 50% 0% */
      BODY { background: url(banner.jpeg) center } /* 50% 50% */
      BODY { background: url(banner.jpeg) bottom } /* 50% 100% */

      background属性是以上背景属性的快捷方式,属性和顺序如下:

      属性名称: 'background'
      属性值: <'background-color'> || <'background-image'> || <'background-repeat'> || <'background-attachment'> || <'background-position'>
      适合对象: 所有元素
      是否继承: no
      百分比备注: 只在background-position中容许使用